package cn.yi.medicalsys.dao.impl;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import cn.yi.medicalsys.dao.RegisterDao;
import cn.yi.medicalsys.pojo.Register;
import cn.yi.medicalsys.utils.BaseDao;

public class RegisterDaoImpl extends BaseDao implements RegisterDao {
	
	@Override
	public List<Register> findRegisterBydate(String date) throws Exception {
		StringBuffer preparedSql=new StringBuffer();
		Register register=null;
		List<Register> list=new ArrayList<Register>();
		List<Object> listParams=new ArrayList<Object>();
		preparedSql.append("SELECT reid,reDate,reState,reVerid,uid FROM register ");
		preparedSql.append("WHERE 1=1   ");
		if(date!=null && !date.equals("")){
			preparedSql.append(" and DATE(reDate)=?  ");
			listParams.add(date);
		}
		preparedSql.append("ORDER BY reState,reDate DESC ");
		Object[] params=listParams.toArray();
		ResultSet rs=super.executeQuery(preparedSql.toString(), params);
		System.out.println(preparedSql.toString());
		while(rs!=null && rs.next()){
			register=new Register();
			register.setReId(rs.getInt("reid"));
			register.setReDate(rs.getTimestamp("reDate"));
			register.setReState(rs.getInt("reState"));
			register.setReVerId(rs.getString("reVerid"));
			register.setuId(rs.getInt("uid"));
			list.add(register);
		}
		return list;
	}

	@Override
	public int updateRegisterByNo(Integer idreg) throws Exception {
		String preparedSql="UPDATE register SET reState=1 WHERE reid=? ";
		Object[] params={idreg};
		int row=super.executeUpdate(preparedSql, params);
		return row;
	}

}
